// import * as React from 'react';
import { useState, useEffect, useRef } from 'react';
import './psDetail.less';
import {
  Input,
  Descriptions,
  Button,
  Table,
  DatePicker,
  Form,
  Select,
} from 'antd';
import { history, Link, useRequest } from 'umi';

const { Option } = Select;
import { UploadOutlined } from '@ant-design/icons';
import styles from '@/pages/admin/mark/personScore.less';
import request from '@/http';
import qs from 'qs';
import { Homework } from '@/pages/login/service';

const { RangePicker } = DatePicker;
export default (props: any) => {
  const courseId: number = props.location.state.courseId;
  const studentId: number = props.location.state.studentId;

  const dataDetail = props.location.state;

  const [dataSource, setDataSource] = useState<any[]>([]);
  const [dataSource1, setDataSource1] = useState<any[]>([]);

  const loadDataSource = async () => {
    const result: any = await request.get(
      '/api/admin/adminScore/getTrainTeacher?courseId=' + courseId,
    );
    console.log(result);
    if (result && result.code === 200) {
      setDataSource1(result.data);
    }
  };

  //个人历史作业  下面table
  const allWork = async () => {
    const result: any = await request.get(
      '/api/admin/adminScore/getStudentHomeWork?size=5&current=1&studentId=' +
        studentId +
        '&courseId=' +
        courseId,
    );
    console.log(result);
    if (result && result.code === 200) {
      const data: any = result.data.records.map((user: any) => ({
        key: `user_${user.homeworkDetailsId}`,
        id: user.homeworkDetailsId, // id
        homeworkDetailsId: user.homeworkDetailsId, // 作业id
        title: user.title, // 	作业主题
        issuedTime: user.issuedTime, // 作业发布时间
        score: user.score, // 	得分
        submitStatus: user.submitStatus == '1' ? '按时' : '延期', // 	作业提交情况
        studentId: user.studentId, // 学生id
        teacherName: user.teacherName, // 作业发布老师
        actualSubmitTime: user.actualSubmitTime, //	完成时间
        submitTime: user.submitTime, //	作业截止日期
      }));
      setDataSource(data);
    }
  };

  //生命周期函数
  useEffect(() => {
    loadDataSource();

    allWork();
  }, []);

  return (
    <>
      <div className="absence_title" style={{ marginBottom: '30px' }}>
        <div className="search" style={{ width: '1400px', height: '380px' }}>
          <div className="title">个人综合得分</div>
          <div className={styles.searchForm}>
            {
              <>
                <Form layout="inline" className="psdForm">
                  <Form.Item
                    style={{ width: 300 }}
                    label="姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名"
                    name="teacherName"
                    initialValue=""
                  >
                    {/*<Input className='teacherInput' placeholder="模糊查询"/>*/}
                    <Descriptions.Item label="姓名">
                      {dataDetail?.studentName}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="性别"
                    name="jobNumber"
                    initialValue=""
                  >
                    <Descriptions.Item label="性别">
                      {dataDetail?.sex}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="学号"
                    name="identity"
                    initialValue=""
                  >
                    <Descriptions.Item label="学号">
                      {dataDetail?.userNo}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="院系"
                    name="phone"
                    initialValue=""
                  >
                    <Descriptions.Item label="院系">
                      {dataDetail?.collegesName}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="实训课程"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="实训课程">
                      {dataDetail?.courseName}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="专业"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="专业">
                      {dataDetail?.majorName}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="实训老师"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="实训老师">
                      {dataSource1}
                    </Descriptions.Item>
                  </Form.Item>
                  <Form.Item
                    style={{ width: 300 }}
                    label="责任老师"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="责任老师">
                      {dataDetail?.responsibilityTeacher}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="项目组"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="项目组">
                      {dataDetail?.teamName}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="小组长"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="小组长">
                      {dataDetail?.majorName}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 600 }}
                    label="项目角色"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="项目角色">
                      {dataDetail?.position}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 1000 }}
                    label="综合打分"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="项目角色">
                      {dataDetail?.score}
                    </Descriptions.Item>
                  </Form.Item>

                  <Form.Item
                    style={{ width: 300 }}
                    label="评语"
                    name="status"
                    initialValue=""
                  >
                    <Descriptions.Item label="项目角色">
                      {dataDetail?.comments}
                    </Descriptions.Item>
                  </Form.Item>
                </Form>
              </>
            }
          </div>
        </div>
      </div>

      <Table
        style={{ width: '1500px' }}
        columns={[
          {
            title: '作业主题',
            dataIndex: 'title',
            align: 'center',
          },
          {
            title: '下发老师',
            dataIndex: 'teacherName',
            align: 'center',
          },
          {
            title: '下发时间',
            dataIndex: 'issuedTime',
            align: 'center',
          },
          {
            title: '提交时间',
            dataIndex: 'submitTime',
            align: 'center',
          },
          {
            title: '实际提交时间',
            dataIndex: 'actualSubmitTime',
            align: 'center',
          },
          {
            title: '提交情况',
            dataIndex: 'submitStatus',
            align: 'center',
          },
          {
            title: '作业得分',
            dataIndex: 'score',
            align: 'center',
          },
          {
            title: '操作',
            dataIndex: 'kind',
            align: 'center',
            render: (row: any) => (
              <>
                <Button
                  type="link"
                  onClick={() => {
                    Homework.saveHomeworkIds({ id: row.id, state: 1 });
                    history.push('/global/homework/details');
                  }}
                >
                  查看详情
                </Button>
              </>
            ),
          },
        ]}
        dataSource={dataSource}
        size="middle"
      />
      <p>
        <Button>
          <Link to="../mark/personScore">返回</Link>
        </Button>
      </p>
    </>
  );
};
